package com.freecycle.sg.utils;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.provider.Settings;

public class ConnectionHelper {

	public static boolean isWifiEnable(final Context context) {
		WifiManager wifiManager = ((WifiManager) context
				.getSystemService(Context.WIFI_SERVICE));
		return wifiManager.isWifiEnabled();
	}

	public static AlertDialog toEnableWifi(final Context context) {
		AlertDialog.Builder builder = new AlertDialog.Builder(context);
		builder.setIcon(android.R.drawable.ic_dialog_alert);
		builder.setTitle("Improve My Location");
		builder.setMessage("Not all location sources are currently enabled. "
				+ "For the fastest and most accurate location detection:\n\n"
				+ "*Turn on Wifi in location settings");
		builder.setPositiveButton("Settings",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS);
						context.startActivity(intent);
						dialog.dismiss();
					}
				});
		builder.setNegativeButton("Skip",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
					}
				});
		return builder.create();
	}

}
